package DataStructureAndAlgorithm.AcWing_每日一题.模拟;
//链接：https://www.acwing.com/problem/content/3827/

import java.util.Scanner;

class AcWing_3824{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();

        for (int z = 0; z < t; z++){
            int n = in.nextInt();
            int[] nums = new int[n];
            int res = 0;
            for (int i = 0; i < n; i++){
                nums[i] = in.nextInt();
            }

            for (int i = 1; i < n - 1; i++){
                if (nums[i] == 0 && nums[i - 1] == 1 && nums[i + 1] == 1)nums[i] = 2;
            }

            for (int i = 0; i < n; i++){
                if (nums[i] != 0)res++;
            }

            System.out.println(res);
        }
        in.close();
    }
}